<?php
//醒计算；；；；；
class PHZ_Xing
{

    /**
     * 翻醒计算
     * @param $room_id
     * @param $card_info  这里是胡牌人的牌面信息数组
     * @param $card_number
     * @param $mode       模式：fan为翻醒，sui为随醒；
     * @返回：囤数（其实就是*3）的息数
     */
    public static function __Xing_Calculation( $room_id , $card_info , $card_number , $mode , $db_connect ){
        $is_haidi = false;
        if( $mode == "fan" ) {//翻醒：----  规则：胡牌后，再摸一张，手牌里面有几张就加几囤，胡海底是胡牌即为醒牌
            $xing_card = PHZ_Tools::__get_next_number($db_connect, $room_id);
            if ((int)$xing_card <= 0 || $xing_card == null || $xing_card == "") {
                $xing_card = $card_number;
                $is_haidi  = true;
            }
        }else if( $mode == "sui" ){//随醒：----  规则：胡牌的牌，胡牌者手里有几张，就加几囤
            $xing_card = $card_number;
        }else{
            return 0;
        }
        $xingpaiCount = 0;
        #.计算手里有多少个醒牌 - 手牌 + 下牌,共有多少个
        $sp = $card_info['sp'];$sp = explode( "," , $sp );
        foreach ( $sp as $key => $value ){
            if( $value != "" && $value == $xing_card ){
                $xingpaiCount++;
            }
        }
        $xp = $card_info['xp'];$xp = explode( "," , $xp );
        foreach ( $xp as $key => $value ){
            #.拆解下牌
            $xp_exp = explode("_" , $value );
            foreach ( $xp_exp as $key_1 => $value_1 ) {
                #.比较
                if ($value_1 != "" && $value_1 == $xing_card) {
                    $xingpaiCount++;
                }
            }
        }
        #.控制数量；翻新最多可以有4个；但是如果是海底的情况下；还是4个，就有问题了；这个时候强制变3个
        if( $mode == "fan" && $is_haidi == true && $xingpaiCount == 4 ) {
            $xingpaiCount = 3;
        }
        #.控制数量；随醒最多可以有3个
        if( $mode == 'sui' && $xingpaiCount == 4 ){
            $xingpaiCount = 3;
        }
        #.返回胡息数
        if( $xingpaiCount <= 0 ){
            return array('huxi' => 0 , 'xing_card' => $xing_card , 'xing_count' => 0 );
        }else{
            return array('huxi' => ($xingpaiCount * 3) , 'xing_card' => $xing_card , 'xing_count' => $xingpaiCount);
        }
    }


}